#include<stdio.h>
#include<pthread.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
char buff[1024];
void thread_exit(void *arg)
{
    printf("%s is exit\n",(char *)arg);
}
void *pthread_in(void *arg)
{
    while (1)
    {
        
        scanf("%s",buff);
    }
    
}
void *pthread_out(void *arg)
{
    pthread_cleanup_push(thread_exit,(void *)"pthread_out");
    while (1)
    {
        if(strcmp(buff,"exit") == 0 )
        {
            pthread_exit(NULL);
        }
        if(strlen(buff)>0)
        {
            printf("%s\n",buff);
            memset(buff,0,1024);
        }
        sleep(1);
        
    }
    pthread_cleanup_pop(!0);
    
}
int main(int argc,char **argv)
{
    pthread_t pin;
    pthread_t pout;
    pthread_create(&pin,NULL,pthread_in,NULL);
    pthread_create(&pout,NULL,pthread_out,NULL);
    // pthread_join(pin,NULL);
    // pthread_join(pout,NULL);
    pause();
    return 0;
}